package com.heyqing.medium.day2;

/**
 * ClassName:MaxArea
 * Package:com.heyqing.medium.day2
 * Description:
 *
 * @Date:2024/10/3
 * @Author:Heyqing
 */
public class MaxArea {
    public int maxArea(int[] height) {
        int maxS = 0, left = 0, right = height.length - 1;
        while (left < right) {
            int s = (right - left) * Math.min(height[left], height[right]);
            maxS = Math.max(s, maxS);
            if (height[left] > height[right]){
                right--;
            }else {
                left++;
            }
        }
        return maxS;
    }

//    int maxS = 0, leftLine = 0;
//    // s = (i - leftLine) * Math.min(height[i],height[leftLine])
//        for (int i = 1; i < height.length; i++) {
//        if (leftLine == height.length - 1) break;
//        int s = (i - leftLine) * Math.min(height[i], height[leftLine]);
//        maxS = Math.max(s, maxS);
//        if (i == height.length - 1) {
//            while (leftLine < height.length - 1) {
//                leftLine++;
//                if (height[leftLine - 1] < height[leftLine]) break;
//            }
//            i = leftLine;
//        }
//    }
//        return maxS;
}
